<?php
?>
<script language="javascript">
	jQuery(document).ready(function(){
		jQuery('#list_express').jqGrid({
			url: '<?=site_url() ?>/gonapi/getData/1/',
			mtype: 'POST',
            datatype: 'json',
            colNames:['ID','Referencia', 'Tipo','Registro','Fecha R.','D.U.','Etapa A.','Estatus','Etapa',
                      'Total','User','Responsable'],
                     colModel :[
                          {name:'IdCompania', index:'IdCompania', width:5,hidden:true},
                          {name:'NombreCompania', index:'NombreCompania', width:80},
                          {name:'IdServicio', index:'IdServicio', width:40},
                      	  {name:'FechaUsrCompania', index:'FechaUsrCompania', width:40},
                       	  {name:'FechaSistema', index:'FechaSistema', width:40},
                      	  {name:'dias', index:'dias', width:20},
                      	  {name:'IdEtapa',index:'idStatu',width:35},
                      	  {name:'IdEstatus',index:'idStatu',width:35},
                      	  {name:'Etapa', index:'Etapa', width:32},
                      	  {name:'Total', index:'Total', width:32},
                      	  {name:'User', index:'IdUsuario', width:35},
                      	  {name:'Responsable', index:'IdResponsable', width:40}],
            pager: jQuery('#pager_express'),
            hiddengrid: false,
            sortname: 'FechaSysCompania',
            rowNum:30,       
            rowList:[30,40],
            sortorder: "ASC",
            height: '100%',
            width: '610',
            imgpath: _base_url + 'public/css/jqgrid/flex/images',
            viewrecords: true,
            multiselect: true,
            onSelectRow: function(ids){
                
                filaSeleccionada = $("#list_express").getRowData(ids);
 				
             },
            adjacents: 4,
            jsonReader: { repeatitems : false, id_Categoria: "0" }
        }).navGrid('#pager_express',{add:false,del:false,edit:false,search:false,position:"left"})
        
        .navButtonAdd('#pager_express',{caption:"", buttonimg: _base_url + "public/css/jqgrid/flex/images/text_columns.png", onClickButton:function(){ jQuery("#list").setColumns();}})
         <?php if ($this->session->userdata('LOGGED_DEPAR') == 4 || $this->session->userdata('LOGGED_DEPAR') == 1): ?>
          .navButtonAdd('#pager_express',{caption:"", buttonimg: _base_url + "public/img/icons/page_white_delete.png", onClickButton:function(){
              var id = jQuery('#list_express').getGridParam('selarrrow');
              var id=lol;
                if (id.length > 0){  
            	      var ret = jQuery("#list_express").getRowData(id);
                      window.location = _site_url + '/main_tran/hsegui/' + ret.id_Categoria;
            
        } else { jAlert('Debe seleccionar al menos una compania'); }
        return false; } })
        <?php endif;?>
        .navButtonAdd('#pager_express',{caption:"Agregar", buttonimg: _base_url + "public/images/new.png", onClickButton:function()
        {window.location = _site_url + "/trancrearcompania/addCompania";}})

        .navButtonAdd('#pager_express',{
       	   caption:"Detalles", 
        	  buttonimg: _base_url + "public/images/new.png", 
      	   onClickButton: function(){ 
      		   var idFila = jQuery('#list_express').getGridParam('selarrrow');
      		   if(idFila.length == 1){
      			   filaSeleccionada = $("#list_express").getRowData(idFila);
                    	window.location = '<?php echo site_url()?>/indicadoresseguimientoci/companyDetails/'+filaSeleccionada['IdCompania'];
          	   }else if(idFila.length >= 2){
          		   jAlert("Solo puedes seleccionar un registro a la vez\npara mostrar los detalles");
                 }else{
  				jAlert("Debe seleccionar un registro");
                 }   
      	    }
      	 })

       .navButtonAdd('#pager_express',{caption:"Send Mail.", buttonimg: _base_url + "public/img/icons/mail-ico.png", onClickButton:function(){ 
        var id = jQuery('#list_express').getGridParam('selarrrow');
      	if (id.length > 0) {
          	 
      		 var s; 
          	 s = jQuery("#list_express").getGridParam('selarrrow'); 
          	 var ret = jQuery("#list_express").getRowData(s[2]);
          	 var miArray = ''; 
               var companiaMsg = '';
               
          	 for(var i = 0;i < id.length; i++)
          	 {
          	 	if(miArray.length > 0)
          	 	{
          	 	   miArray= miArray+'-'+jQuery("#list_express").getRowData(s[i]).IdCompania;
          	 	}
          	 	else
          	 	{
          	 	   miArray=jQuery("#list_express").getRowData(s[i]).IdCompania;
          	 	}
                var  index = i + 1;
          	 	companiaMsg = companiaMsg+index+'.'+jQuery("#list_express").getRowData(s[i]).NombreCompania+'<br/>';
          	  }

        	      msg = '<font style="color:#1C1C1C;font-weight:600;font-size: 14px">Enviar Mail a </font> <br/> <font style="color: #0404B4;font-weight:500;font-size: 10px">'+companiaMsg+'</font>';
                 jConfirm(msg, 'Dialogo de Confirmacion', function (r) {
                 if(r) {
                   id=jQuery('#list_express').getGridParam('selrow');
                   ret = jQuery("#list_express").getRowData(id);
                   window.location = _site_url + '/setupseguimiento/sendmail/'+miArray;
                   }
                });
            }else { jAlert('Debe seleccionar un registro'); }
                    return false; } })


              
	});
	
	var flAuto = true;
	 var timeoutHnd; 

	 function doSearchExpress(ev)
	 { 
	       if(!flAuto) return; 
	       // var elem = ev.target||ev.srcElement; 
	       if(timeoutHnd) 
	           clearTimeout(timeoutHnd); 
	           timeoutHnd = setTimeout(gridReloadExpress,500); 
	 }
	  
	 function enableAutosubmitExpress(state)
	 { 
	       flAuto = state; 
	       jQuery("#submitButton").attr("disabled",state); 
	 }
	 
	 function gridReloadExpress()
	 { 
	     var color_mask = jQuery("#color").val();
	     jQuery("#list_express").setGridParam({url :'<?=site_url() ?>/gonapi/getData/1/'+color_mask, page : 1}).trigger('reloadGrid');
	      
	 }
</script>

<div class="table_container">
	<a href="<?php echo site_url();?>/indicadoresgventas24h"><font size = "3%" >Indicadores G-VENTAS-24h</font></a>
	<font size = "3%" >|</font>
	<b style="background-color: green;"><font size = "2%" color="white">Indicador Actual = <?=$porcentajeEstatusExpress['verdes']?>%</font></b>
	<font size = "3%" >|</font>
	<b style="background-color: yellow;"><font size = "2%" color="black">Observaci&oacute;n Amarillos = <?=$porcentajeEstatusExpress['amarillos']?>%</font></b>
	<font size = "3%" >|</font>
	<b style="background-color: #2E9AFE;"><font size = "2%" color="black">Balance Actual = <?=$porcentajeEstatusExpress['balanceActual']?></font></b>
	<table>
		<tr>
			<td><div id="titulo">Listado de Campa&ntilde;ias Express (24 horas)</div></td>
			
		</tr>
		<tr>
			<td style="background: #D9E6F0;border: 1px solid #C3AA64; height: 23px">
			&nbsp;&nbsp;&nbsp;&nbsp;<b>Color:<b/> <select id='color' onChange='doSearchExpress(arguments[0]||event)' ><option></option> <?php foreach ($colores as $k): echo '<option value="'.$k.'">'.$k.'</option>'; endforeach;?></select>
			</td>
		</tr>
		<tr>
			<td>
				<table id="list_express" class="scroll"></table>
				<div id="pager_express" class = "scroll" style="text-aling:center;"></div>
			</td>
		</tr>
	</table>
</div>